/**
 * Created by Dean on 2018-8-27.
 */
class BhJiFenCell extends eui.ItemRenderer{

    static CELLWIDTH = 0;
    private showPayIndex:number = -1;
    private bg:egret.Bitmap;
    private img_bg:egret.Bitmap;
    private img:eui.Image;
    private level_name:egret.Bitmap;
    private index_img:egret.Bitmap;
    private index_text:egret.TextField;
    private name_text:egret.TextField;
    private jifen_text:egret.TextField;
    private bh_img:egret.Bitmap;
    private bh_name:egret.TextField;
    private gr_jifen_time:egret.TextField;
    private gr_jifen_title:egret.TextField;
    private bh_time_bg:egret.Bitmap;
    private bz:egret.Bitmap;
    private jf_bg:egret.Bitmap;
    private box_img:egret.Bitmap;
    private rank:number = 1;
    static jfView = null;


    constructor(){
        super();
        this.width = BhJiFenCell.CELLWIDTH;
        this.height = 150;

        this.bg = utils.createBitmapByName("hi_rank_cell1"); 
        this.bg.height = 146;
        this.bg.width = this.width - 30;
        this.bg.y = (this.height - this.bg.height)/2;
        this.bg.x = 15; 
        // this.addChild(this.bg);

        this.bh_img = utils.createBitmapByName("bhicon"); 
        // this.bh_img.height = 146;
        // this.bh_img.width = this.width - 30;
        this.bh_img.y = 15;
        this.bh_img.x = 100; 
        this.addChild(this.bh_img);
        
        this.bh_name = utils.createTextField();
        this.bh_name.size = 24;
        this.bh_name.textColor = 0xFFFFFF;
        this.bh_name.stroke = 2;
        this.bh_name.bold = true;
        this.bh_name.strokeColor = 0x6A410D;
        this.bh_name.x = 170;
        this.bh_name.y = 20;
        this.bh_name.width = 220;
        this.bh_name.textAlign = "left";
        this.addChild(this.bh_name);

        this.img_bg = utils.createBitmapByName("level5");
        this.img_bg.width = 60;
        this.img_bg.height = 60;
        this.img_bg.x = 100;
        this.img_bg.y = 65;
        // this.addChild(this.img_bg);

        this.img = new eui.Image();
        this.img.width=50;
        this.img.height=50;
        this.img.x = 105;
        this.img.y = 70;
        var maskShape = new egret.Shape();
        maskShape.graphics.beginFill(0x000000,1);
        maskShape.graphics.drawRoundRect(this.img.x , this.img.y ,50,50,20,20);
        maskShape.graphics.endFill();
        this.addChild(maskShape);
        this.img.mask = maskShape;

        
        this.level_name = utils.createBitmapByName("levelname1");
        this.level_name.x = 105;
        this.level_name.y = 100;
        this.level_name.width = 75;
        this.level_name.height = 22;

        this.index_img = utils.createBitmapByName("1");
        this.index_img.x = 15;
        this.index_img.y = (this.height - this.index_img.height)/2;
        // this.addChild(this.index_img);

        this.index_text = utils.createTextField();
        // this.index_text.text = "1";
        this.index_text.size = 35;
        this.index_text.textColor = 0xFFEA70;
        this.index_text.stroke = 2;
        this.index_text.bold = true;
        this.index_text.strokeColor = 0x6A410D;
        this.index_text.x = 25;
        this.index_text.y = 60;
        this.index_text.width = 70;
        // this.addChild(this.index_text);

        this.name_text = utils.createTextField();
        this.name_text.size = 24;
        this.name_text.textColor = 0x6A410D;
        this.name_text.bold = true;
        this.name_text.width = 270;
        this.name_text.y = 90;
        this.name_text.x = 170;
        this.name_text.textAlign = "left";
        this.addChild(this.name_text);

        // this.bh_time_bg = utils.createBitmapByName("bh_time1");
        // this.bh_time_bg.x = 380;
        // this.bh_time_bg.y = 5;
        // this.addChild(this.bh_time_bg);

        // this.gr_jifen_time = utils.createTextField();
        // // this.gr_jifen_time.text = "2018.11.14 18:22:22";
        // this.gr_jifen_time.size = 18;
        // this.gr_jifen_time.textColor = 0x6A410D;
        // this.gr_jifen_time.x = 400;
        // this.gr_jifen_time.y = 10;
        // this.addChild(this.gr_jifen_time);

        this.jf_bg = utils.createBitmapByName("jf_bg_1");
        this.jf_bg.width = 140;
        this.jf_bg.height = 75;
        this.jf_bg.x = 440;
        this.jf_bg.y = 10;
        this.addChild(this.jf_bg);

        this.gr_jifen_title = utils.createTextField();
        this.gr_jifen_title.text = "帮会积分";
        this.gr_jifen_title.size = 24;
        this.gr_jifen_title.textColor = 0x6A410D;
        this.gr_jifen_title.bold = true;
        this.gr_jifen_title.x = 450;
        this.gr_jifen_title.y = 20;
        this.gr_jifen_title.width = 120;
        this.addChild(this.gr_jifen_title);

        this.jifen_text = utils.createTextField();
        // this.jifen_text.text = "300";
        this.jifen_text.size = 28;
        this.jifen_text.textColor = 0xF6CD57;
        this.jifen_text.stroke = 2;
        this.jifen_text.bold = true;
        this.jifen_text.strokeColor = 0x6A410D;
        this.jifen_text.x = 450;
        this.jifen_text.y = 50;
        this.jifen_text.width = 130;
        // this.jifen_text.textAlign = "left";
        this.addChild(this.jifen_text);

        this.box_img = utils.createBitmapByName("box_1");
        this.addChild(this.box_img);


        //弹出奖励明细
        this.box_img.touchEnabled = true;
        this.box_img.addEventListener(egret.TouchEvent.TOUCH_TAP,function(evt:egret.TouchEvent){
             BhJiFenCell.jfView.showAwardList(this.rank,this.box_img.x,evt,"bh");
        },this);
    }

    protected dataChanged(): void {
        var data = this.data;
        this.rank = data.rank;
        if(data.rank > 3){
            this.index_text.text = data.rank;
            if(this.contains(this.index_img)){
               this.removeChild(this.index_img);
            }
            this.addChild(this.index_text);

            this.bg.texture = RES.getRes("hi_rank_cell4");
            this.addChild(this.bg);

            // this.bh_time_bg.texture = RES.getRes("bh_time2");
            // this.bh_time_bg.x = 390;

            this.jf_bg.visible = false;

            //判断是否显示宝箱
            if(data.rank <= GameData.gangRank.length){
                this.box_img.visible = true;
                this.box_img.texture = RES.getRes("box_4");
            }else{
                this.box_img.visible = false;
            }
            
        }else{
            if(this.contains(this.index_text)){
               this.removeChild(this.index_text);
            }
            this.bg.texture = RES.getRes("hi_rank_cell"+data.rank);
            this.addChild(this.bg);

            this.index_img.texture = RES.getRes(data.rank+"");
            this.addChild(this.index_img);

            // this.bh_time_bg.texture = RES.getRes("bh_time1");

            this.jf_bg.visible = true;
            this.jf_bg.texture = RES.getRes("jf_bg_"+data.rank);

            this.box_img.texture = RES.getRes("box_"+data.rank);
        }
        this.img_bg.texture = RES.getRes("level"+data.level_no);
        this.addChild(this.img_bg);
        this.img.source = data.head_url;
        this.addChild(this.img);

        this.box_img.anchorOffsetX = this.box_img.width/2;
        this.box_img.anchorOffsetY = this.box_img.height/2;
        this.box_img.y = this.jf_bg.y + this.jf_bg.height - 5 + this.box_img.height/2;
        this.box_img.x = 520;

        //帮会角标
        this.bz = utils.createBitmapByName("bz");
        this.bz.x = 100;
        this.bz.y = 65; 
        this.bz.width = 35;
        this.bz.height = 40;
        this.addChild(this.bz);

        this.level_name.texture = RES.getRes("levelname"+data.level_no);
        this.addChild(this.level_name);


        var name_text_str = "帮主："+data.nickname;
        name_text_str = utils.getChar(name_text_str,30);
        this.name_text.text = name_text_str;


        // this.gr_jifen_time.text = data.last_add_time.replace(/-/g,'.');

        this.jifen_text.text = data.total_score;

        var bh_name_str = data.gang_name;
        bh_name_str = utils.getChar(bh_name_str,24);
        this.bh_name.text = bh_name_str;

        this.setChildIndex(this.bg,0);

        if(data.rank == 1){
           this.gr_jifen_title.textColor = 0xFCB42E;
           this.jifen_text.strokeColor = 0x6A410D;
           this.gr_jifen_title.bold = true;
           this.gr_jifen_title.stroke = 1;
        }else if(data.rank == 2){
           this.gr_jifen_title.textColor = 0xECECEC;
           this.jifen_text.strokeColor = 0x6E6E6E;
           this.gr_jifen_title.bold = true;
           this.gr_jifen_title.stroke = 1;
        }else if(data.rank == 3){
           this.gr_jifen_title.textColor = 0xF7C97B;
           this.jifen_text.strokeColor = 0x6A410D;
           this.gr_jifen_title.bold = true;
           this.gr_jifen_title.stroke = 1;
        }else{
           this.gr_jifen_title.textColor = 0x6A410D;
           this.jifen_text.strokeColor = 0;
           this.gr_jifen_title.bold = false;
           this.gr_jifen_title.stroke = 0;
        }

    }

    
}